﻿/*
*    Qizx/open 3.0 beta
*
* This code is the open-source version of Qizx.
* Copyright (C) 2004-2009 Axyana Software -- All rights reserved.
*
* The contents of this file are subject to the Mozilla Public License 
*  Version 1.1 (the "License"); you may not use this file except in 
*  compliance with the License. You may obtain a copy of the License at
*  http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
*  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
*  for the specific language governing rights and limitations under the
*  License.
*
* The Initial Developer of the Original Code is Xavier Franc - Axyana Software.
*
*/
using System;
using DataModelException = System.Qizx.Api.DataModelException;
using EvaluationException = System.Qizx.Api.EvaluationException;
using Node = System.Qizx.Api.Node;
using QName = System.Qizx.Api.QName;
using QizxException = System.Qizx.Api.QizxException;
using XMLPullStream = System.Qizx.Api.XMLPullStream;
using PushStreamToDOM = System.Qizx.Api.Util.PushStreamToDOM;
using XQDateTimeBase = System.Qizx.Api.Util.XQDateTimeBase;
using DateTimeException = System.Qizx.Api.Util.XQDateTimeException;
using Duration = System.Qizx.Api.Util.XQDuration;
using NamespaceContext = System.Qizx.Util.NamespaceContext;
using Comparison = System.Qizx.Util.Basic.Comparison;
using FileUtil = System.Qizx.Util.Basic.FileUtil;
using ComparisonContext = System.Qizx.XQuery.ComparisonContext;
using XQItem = System.Qizx.XQuery.XQItem;
using XQValue = System.Qizx.XQuery.XQValue;
using StringValue = System.Qizx.XQuery.Dt.StringValue;
using UntypedAtomicType = System.Qizx.XQuery.Dt.UntypedAtomicType;
using URI = System.Uri;

namespace System.Qizx.Xdm
{
    // sibling sequence
    internal class SSequence : NodeSequenceBase
    {
        virtual public BasicNode BaseNode
        {
            get
            {
                return current;
            }

        }
        internal static SSequence emptySequence = new SSequence(null);

        internal bool started = false;

        protected internal XdmNode current, first;

        internal SSequence(XdmNode first)
        {
            this.first = this.current = first;
        }

        public override XQValue BornAgain()
        {
            return new SSequence(first);
        }

        public override bool Next()
        {
            if (started && current != null)
                current = current._nextSibling;
            started = true;
            return current != null;
        }

        public override Node GetNode()
        {
            return current;
        }

        public override BasicNode GetBasicNode()
        {
            return current;
        }

        // ------------ NodeSequence:

        public virtual bool nextNode()
        {
            return Next();
        }

        public virtual Node currentNode()
        {
            return current;
        }

        public virtual NodeSequenceBase reborn()
        {
            return (NodeSequenceBase)BornAgain();
        }
    }
}
